package com.neusoft.service.impl;

//根据子项目名字不同而不同
import com.neusoft.mapper.BVirtualWalletMapper;
import com.neusoft.po.BVirtualWallet;
import com.neusoft.service.BVirtualWalletService;

//统一
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class BVirtualWalletServiceImpl implements BVirtualWalletService {
    @Autowired
    private BVirtualWalletMapper bVirtualWalletMapper;

    //新建一个钱包
    @Override
    public int saveBVirtualWallet(Integer businessId) {
        return bVirtualWalletMapper.saveBVirtualWallet(businessId);
    }

    //查询一个钱包
    @Override
    public BVirtualWallet getBVirtualWalletByBusinessId(Integer businessId){
        return bVirtualWalletMapper.getBVirtualWalletByBusinessId(businessId);
    }

    @Override
    public int rechargeByBusinessId(Integer businessId,BigDecimal add_balance){
        //从其他渠道将款转到elm下，具体内容省略
        if(add_balance.compareTo(BigDecimal.ZERO)<0){
            return -2;
        }
        BigDecimal balance = bVirtualWalletMapper.getBVirtualWalletByBusinessId(businessId).getBalance();
        balance = balance.add(add_balance);
        return bVirtualWalletMapper.updateBVirtualwallet(businessId,balance);
    }

    @Override
    public int payoutByBusinessId(Integer businessId, BigDecimal sub_balance) {
        //提现
        if(sub_balance.compareTo(BigDecimal.ZERO)<0){
            return -2;
        }
        BigDecimal balance = bVirtualWalletMapper.getBVirtualWalletByBusinessId(businessId).getBalance();
        balance = balance.subtract(sub_balance);
        return bVirtualWalletMapper.updateBVirtualwallet(businessId,balance);
    }
}

